from .. import db

import datetime


class Question(db.Model):
    __tablename__ = 'question'
    id = db.Column(db.Integer, primary_key=True)
    ques_tagid = db.Column(db.Integer)
    ques_title = db.Column(db.Text)
    content = db.Column(db.Text)
    ques_answer = db.Column(db.JSON)
    ques_score = db.Column(db.Integer, default=10)
    status = db.Column(db.SmallInteger, comment='0: except, 1: normal', default=1)
    valid = db.Column(db.SmallInteger, comment='0: deleted, 1: valid', default=1)
    create_time = db.Column(db.DateTime, default=datetime.datetime.now())
    update_time = db.Column(db.DateTime, default=datetime.datetime.now())

    def get_ques_tag(self):
        return {1: '单选题', 2: '判断题', 3: '填空题', 4: '论述题'}.get(self.ques_tagid, '')

    def get_status(self):
        return {0: '题目有误', 1: '正常'}.get(self.status, '')

    def __repr__(self):
        return f"<Question {self.id}:{self.ques_title}>"
